package com.css.common.core.exception;


import com.css.common.core.constant.ResultCode;

/**
 * @ClassName ServiceException
 * @Auther qiumengmeng
 * @Date 2024/8/7 上午11:22
 */
public class ServiceException extends RuntimeException implements ResultCode {
    private final int code;
    private final String msg;

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    public ServiceException(int code, String msg) {
        super(code + ":" + msg, null, true, true);
        this.code = code;
        this.msg = msg;
    }

    public ServiceException(String msg) {
        super(msg, null, true, true);
        this.code = -1;
        this.msg = msg;
    }

    public ServiceException(ResultCode resultCode) {
        this(resultCode.getCode(), resultCode.getMsg());
    }

    public ServiceException(ResultCode resultCode, Object... args) {
        this(resultCode.getCode(), String.format(resultCode.getMsg(), args));
    }

    public ServiceException(ResultCode resultCode, String str, Boolean flag) {
        this(resultCode.getCode(), resultCode.getMsg() + ":" + str);
    }
}
